﻿namespace TestTool.GUI
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class TextInput : Form
    {
        private ValidateFunction _validateFunction;
        private Button btnCancel;
        private Button btnOK;
        private IContainer components;
        private Label lblPrompt;
        private TextBox txtInput;

        protected TextInput()
        {
            this.InitializeComponent();
        }

        public TextInput(string caption, string label) : this(caption, label, null)
        {
        }

        public TextInput(string caption, string label, ValidateFunction validateFunction) : this()
        {
            this.lblPrompt.Text = label;
            this.Text = caption;
            this._validateFunction = validateFunction;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if ((this._validateFunction != null) && !this._validateFunction(this.txtInput.Text))
            {
                this.txtInput.Focus();
            }
            else
            {
                base.DialogResult = DialogResult.OK;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.btnCancel = new Button();
            this.btnOK = new Button();
            this.txtInput = new TextBox();
            this.lblPrompt = new Label();
            base.SuspendLayout();
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Location = new Point(0x7f, 0x34);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 9;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnOK.Location = new Point(0x2e, 0x34);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new Size(0x4b, 0x17);
            this.btnOK.TabIndex = 8;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += new EventHandler(this.btnOK_Click);
            this.txtInput.Location = new Point(70, 0x10);
            this.txtInput.Name = "txtInput";
            this.txtInput.Size = new Size(0xa6, 20);
            this.txtInput.TabIndex = 7;
            this.lblPrompt.AutoSize = true;
            this.lblPrompt.Location = new Point(12, 0x13);
            this.lblPrompt.Name = "lblPrompt";
            this.lblPrompt.Size = new Size(0x34, 13);
            this.lblPrompt.TabIndex = 6;
            this.lblPrompt.Text = "Gateway:";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0xf8, 0x54);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOK);
            base.Controls.Add(this.txtInput);
            base.Controls.Add(this.lblPrompt);
            base.FormBorderStyle = FormBorderStyle.FixedDialog;
            base.Name = "TextInput";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Enter Default Gateway";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public string Input
        {
            get
            {
                return this.txtInput.Text;
            }
            set
            {
                this.txtInput.Text = value;
            }
        }
    }
}

